package cn.server;

import java.io.File;
import java.util.List;
import java.util.TimeZone;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.PropertyConfigurator;

import cn.server.util.ServerConfUtil;

/**
 * The Class StartServer. 启动服务类
 */
public class StartServer {

	/**
	 * The main method.
	 *
	 * @param args
	 *            the args
	 */
	public static void main(String[] args) {
		try {
			final TimeZone zone = TimeZone.getTimeZone("GMT+8"); // 获取中国时区
			TimeZone.setDefault(zone); // 设置时区

			PropertyConfigurator.configureAndWatch("config/log4j.properties");
			FileUtils.deleteDirectory(new File("config/receive"));
			List<IServer> list = ServerConfUtil.parseServerList();
			if (list == null || list.size() == 0) {
				System.out.println("server list is empty!now return!");
				return;
			}
			for (int i = 0; i < list.size(); i++) {
				try {
					final IServer server = list.get(i);
					new Thread(new Runnable() {
						@Override
						public void run() {
							server.start();
						}
					}, "server" + i).start();
				} catch (Throwable e) {
					e.printStackTrace();
				}
			}
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}
